package com.realestate.services;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.realestate.constants.ComTxManagerName;
import com.realestate.dao.ProductCommonAttributeValueDao;
import com.realestate.model.BrtbProductCommonAttrValue;

@Service
public class ProductCommonAttributeValueServiceImpl implements ProductCommonAttributeValueService{
	
	@SuppressWarnings("unused")
	private static final Logger LOGGER = Logger.getLogger(ProductCommonAttributeValueServiceImpl.class);
	
	@Autowired
    private ProductCommonAttributeValueDao commonAttributeValueDao;
 
	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void persist(BrtbProductCommonAttrValue instance) {
		commonAttributeValueDao.persist(instance);
		commonAttributeValueDao.flush();
	}

	@Override
	public List<Object[]> getAllCommonAttributesOfAProduct(Long productId) {
		return commonAttributeValueDao.getAllCommonAttributesOfAProduct(productId);
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void deleteAllCommonAttributeValueOfAProduct(Long productId) {
		List<BrtbProductCommonAttrValue> result = commonAttributeValueDao.deleteAllCommonAttributeValueOfAProduct(productId);
		for(BrtbProductCommonAttrValue value: result){
			commonAttributeValueDao.remove(value);
		}
	}

	@Override
	public BrtbProductCommonAttrValue getCommonAttributeValueByProductIdCommonAttributeId(
			Long productId, Long commonAttributeId) {
		return commonAttributeValueDao.getCommonAttributeValueByProductIdCommonAttributeId(productId, commonAttributeId);
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public BrtbProductCommonAttrValue merge(BrtbProductCommonAttrValue instance) {
		BrtbProductCommonAttrValue result = commonAttributeValueDao.merge(instance);
		commonAttributeValueDao.flush();
		return result;
	}
}
